#pragma once
#include "hIntervalMapNode.h"
#include "hIntervalMapIterator.h"

template <typename Key, typename Val>
class hIntervalMap
{
	friend class hIntervalMapNode<Key, Val>;

public:
	using ThisTy = hIntervalMap;
	using KeyTy = hInterval<Key>;
	using Iter = _hIntervalMapIterator<Key, Val, false>;
	using CIter = _hIntervalMapIterator<Key, Val, true>;
	using NodeTy = hIntervalMapNode<Key, Val>;

private:
	NodeTy* _root = NodeTy::_pNil;
	NodeTy* _begNd = NodeTy::_pNil;
	hListNode<Val>* _begValNd = NULL;

public:
	hIntervalMap();
	~hIntervalMap();

	template<typename... Args>
	std::pair<Iter, bool> emplace(const hInterval<Key>& k, Args... args);
	Iter erase(const hInterval<Key>& k);
	Iter erase(Iter it);

	Iter findByRank(size_t r);

	bool check(const KeyTy& k, hEnum fdTy = hIntervalMapFindType::Overlap);
	size_t find(hList<Iter>& fdLst, const KeyTy& k, hEnum fdTy = hIntervalMapFindType::Overlap);
	Iter begin();
	CIter begin() const;
	Iter end();
	CIter end() const;

	void clear();

	size_t size() const { return _root->getSize(); }
	std::ostream& fillDebug(std::ostream& os) const;
};

#include "hIntervalMapImpl.h"